﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyGUI.wcfFlightService;
using MyGUI.Properties;
using Model_Layer;

namespace MyGUI
{
    public partial class ShowTravel : Form
    {
        private wcfFlightService.IService wcfService;
        List<Airport> solutionpath;
        int numPassenger;
        public ShowTravel(List<Airport> dijkstraList, int numPassengers)
        {
            wcfService = new wcfFlightService.ServiceClient();
            numPassenger = numPassengers;
            solutionpath = dijkstraList;
            InitializeComponent();
        }

        private void ShowTravel_Load(object sender, EventArgs e)
        {
            try
            {
                string SourceAirport = solutionpath.Last<Airport>().Name;
                double totalprice = solutionpath.Last<Airport>().Price;
                int totaltraveltime = solutionpath.First<Airport>().Dist;
                string DepatureTime = solutionpath.Last<Airport>().AdjFlight.Timeofdeparture.ToString();
                string DestAirport = solutionpath.First<Airport>().Name;
                string ArrivalTime = solutionpath.First<Airport>().AdjFlight.Timeofarrival;

                int numofstops = 0;
                if (solutionpath.Count > 2)
                {
                    numofstops = solutionpath.Count - 2;
                }
                ListViewItem listviewObj = new ListViewItem(SourceAirport);
                listviewObj.SubItems.Add(DestAirport);
                listviewObj.SubItems.Add(DepatureTime);
                listviewObj.SubItems.Add(ArrivalTime);
                listviewObj.SubItems.Add(totaltraveltime.ToString());
                listviewObj.SubItems.Add(totalprice.ToString());
                listviewObj.SubItems.Add(numofstops.ToString());
                travelsListView.Items.Add(listviewObj);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnShowDetail_Click(object sender, EventArgs e)
        {
            try
            {
                solutionpath.Reverse();
                foreach (Airport a in solutionpath)
                {
                    if (a.PreviousVertex != null)
                    {
                        string SourceAirport = a.PreviousVertex.Name;
                        string DepatureTime = a.AdjFlight.Timeofdeparture;
                        string DestAirport = a.Name;
                        string ArrivalTime = a.AdjFlight.Timeofarrival;
                        string AircraftModel = a.AdjFlight.Objairplane.Model;
                        string FlightID = a.AdjFlight.Idflight.ToString();

                        ListViewItem listviewObj = new ListViewItem(SourceAirport);
                        listviewObj.SubItems.Add(DestAirport);
                        listviewObj.SubItems.Add(DepatureTime);
                        listviewObj.SubItems.Add(ArrivalTime);
                        listviewObj.SubItems.Add(AircraftModel);
                        listviewObj.SubItems.Add(FlightID);
                        listViewFlights.Items.Add(listviewObj);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnBookFlight_Click(object sender, EventArgs e)
        {
            Checkout checkoutObj = new Checkout(numPassenger);
            checkoutObj.Owner = this;
            checkoutObj.Show();
        }


        private void travelsListView_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void listViewFlights_SelectedIndexChanged(object sender, EventArgs e)
        {

        }


    }
}

